<?php

/**
 * This is the model class for table "user".
 *
 * The followings are the available columns in table 'user':
 * @property string $id
 * @property string $username
 * @property string $password
 * @property integer $age
 * @property string $createdDate
 */
class Sample extends ActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user';
	}
	
	public function search()
	{
		$condition = "";
	
		if(!empty($_POST['username']))
			$condition .= " AND t.username LIKE '%" . $_POST['username'] . "%'";
		
		if(!empty($_POST['fullname']))
		{
			$condition .= " AND (t.firstname LIKE '%" . $_POST['fullname'] . "%'";
			$condition .= " OR t.lastname LIKE '%" . $_POST['fullname'] . "%')";
		}
		
		$query = "select * from user t
			WHERE 1 = 1 $condition
		";
		
		$result = $this -> executeAllTotal($query, null, true, "t.createdDate desc");
	
		return $result;
	}
	
}